﻿using Demo.Domains.Entities.Sys;
using Demo.PetaPoco.Application.Dtos.User;
using Demo.PetaPoco.Application.Services.User;
using Microsoft.AspNetCore.Mvc;

namespace Demo.PetaPoco.WebApi.Controllers;

[Route("api/[controller]")]
[ApiController]
public class FakeController(UserService userService) : ControllerBase
{
	/// <summary>
	/// 创建假用户
	/// </summary>
	/// <param name="count"></param>
	/// <returns></returns>
	[HttpGet("generate_faake_users")]
	public async Task<IActionResult> GenerateUsersAsync(int count = 100)
	{
		for (int i = 0; i < count; i++)
		{
			var user = new UserCreateModel
			{
				Name = Faker.Name.FullName(), // 随机生成姓名
				Type = UserType.User, // 用户类型固定为 UserType.User
				Email = Faker.Internet.Email(), // 随机生成邮箱
				Mobile = GeneratePhoneNumber(), // 随机生成手机号码
				DeptId = 1, // 固定为1
				Password = "a123456", // 假设密码为默认值，可以根据需求调整
			};

			await userService.CreateAsync(user);
		}
		return Ok();
	}

	/// <summary>
	/// 生成符合格式的随机手机号码
	/// </summary>
	/// <returns>符合格式的手机号码</returns>
	static string GeneratePhoneNumber()
	{
		var random = new Random();
		// 假设中国手机号码的格式为：1开头，后续11位数字
		string prefix = "1";
		string phoneNumber = prefix + random.Next(100000000, 999999999); // 生成随机数字后拼接
		return phoneNumber;
	}
}
